# -*- coding: utf-8 -*-

from datetime import timedelta

from dateutil.relativedelta import relativedelta

from odoo import models, fields, api
from odoo.exceptions import ValidationError, UserError
import datetime
import json
from odoo.tools.misc import xlwt
import base64
from io import BytesIO


class PurchaseOrderLineWizard(models.TransientModel):
    _name = 'purchase.order.line.wizard'
    date_start=fields.Date(string=u'开始时间')
    date_stop=fields.Date(string=u'结束时间')
    product_id=fields.Many2one('product.product',domain=[('purchase_ok','=',True)])
    partner_id=fields.Many2one('res.partner',domain=[('supplier_rank','>',0)])


    def action_confirm(self):
        domain=[]
        if self.product_id:
            domain=[('product_id', '=', self.product_id.id)]
        if self.partner_id:
            domain=[('partner_id', '=', self.partner_id.id)]
        domain += [('date_order','>=',self.date_start),('date_order','<=',self.date_stop)]

        view_id = self.env.ref('purchase_order_inherit.purchase_order_line_tree_for_invoice').id
        return {'type': 'ir.actions.act_window',
                'name': '采购明细',
                'res_model': 'purchase.order.line',
                'domain':domain,
                'views': [[view_id, 'tree']],
                }





